{#`haystack`会自动的在`templates`文件夹下寻找这个模板文件渲染，#}
{#并且会给这个模板文件传入`page`、`paginator`、`query`等参数。#}
{#其中`page`和`paginator`分别是`django`内置的`Page`类和`Paginator`类的对象#}
{% extends "blog/base.html" %}
{% load blog_tags %}
{% block title %}搜索{% endblock %}
{% block content %}
		<div class="content-body">
			<div class="container">
				<div class="row">
                    <main class="col-md-12">
                          {% if query %}
                            <h1>博客中包含 "{{ query }}"</h1>
                            <h3>
                            查询结果有 {{ paginator.count }} 条
                            </h3>
                            {% for result in page.object_list %}
                                {% with result.object as post %}
                                <article class="post post-{{ forloop.counter }}">
							    <header class="entry-header">
								    <h1 class="entry-title">
									    <a href="{{ post.get_absolute_url }}">{{ post.title }}</a>
								    </h1>
                                    <div class="entry-meta">
                                        <span class="post-category"><a href="#">博客类型</a></span>

                                        <span class="post-date"><a href="#"><time class="entry-date" datetime="2012-11-09T23:15:57+00:00">{{ post.publish}}</time></a></span>

                                        <span class="post-author"><a href="#">{{ post.author }}</a></span>

                                        <span class="comments-link"><a href="">4 评论</a></span>

                                        <span class="views-count"><a href="#">{{ post.views }} 阅读</a></span>
                                    </div>
                                </header>
                                    <div class="entry-content clearfix">
                                        <p>{{ post.body|markdown|truncatewords:30|safe}}</p>
                                        <div class="read-more cl-effect-14">
                                            <a href="{{ post.get_absolute_url }}" class="more-link">继续阅读 <span class="meta-nav">→</span></a>
								        </div>
							        </div>
                            </article>
                                {% endwith %}
                            {% empty %}
                                <p>博客中没有包含 "{{ query }}"的帖子</p>
                            {% endfor %}
                        {% else %}
                            <h1>博客中,未找到: "{{ query }}"</h1>
                        {% endif %}
                        {% if query %}
                            {% if page.object_list%}
                            <div class="read-more ">
                            <nav aria-label="Page navigation">
                            <ul class="pagination">
                                    {#上一页#}
                                     {% if page.has_previous %}
                                        <li><a href="?q={{query}}&amp;page={{ page.previous_page_number }}">
                                            <span aria-hidden="true">&laquo;</span></a></li>
                                     {% else %}
                                          <li class="disabled"><a href="javascript:void(0);">
                                              <span aria-hidden="false">&laquo;</span></a></li>
                                     {% endif %}

                                    {# 左边页码#}
                                    {% if page.has_previous %}
                                        {% if page.number > 4 %}
                                            <li><a href="?q={{query}}&amp;page=1">1</a></li>
                                            <li><a href="javascript:void(0);">...</a></li>
                                            <li><a href="?q={{query}}&amp;page={{ page.number|subtract:'2' }}">{{ page.number|subtract:'2' }}</a></li>
                                            <li><a href="?q={{query}}&amp;page={{ page.number|subtract:'1' }}">{{ page.number|subtract:'1' }}</a></li>
                                        {% else %}
                                            {% if page.number|add:'3' == 5 %}
                                                <li><a href="?q={{query}}&amp;page=1">1</a></li>
                                            {% endif %}
                                            {% if page.number|add:'2' == 5 %}
                                                <li><a href="?q={{query}}&amp;page=1">1</a></li>
                                                <li><a href="?q={{query}}&amp;page=2">2</a></li>
                                            {% endif %}
                                            {% if page.number|add:'1' == 5 %}

                                                <li><a href="?q={{query}}&amp;page=1">1</a></li>
                                                <li><a href="?q={{query}}&amp;page=2">2</a></li>
                                                <li><a href="?q={{query}}&amp;page=3">3</a></li>
                                            {% endif %}
                                        {% endif %}
                                    {% endif %}

                                    {# 当前页#}
                                     <li class="active"><a href="?q={{query}}&amp;page={{ page.number }}">{{ page.number }}</a></li>

                                    {# 右边页码 #}
                                    {% if page.has_next %}
                                        {% if page.number < paginator.num_pages|subtract:'3'%}
                                            <li><a href="?q={{query}}&amp;page={{ page.number|add:'1' }}">{{ page.number|add:'1' }}</a></li>
                                            <li><a href="?q={{query}}&amp;page={{ page.number|add:'2' }}">{{ page.number|add:'2' }}</a></li>
                                            <li><a href="javascript:void(0);">...</a></li>
                                            <li><a href="?q={{query}}&amp;page={{ paginator.num_pages }}">{{paginator.num_pages}}</a></li>
                                        {% else %}
                                            {% if paginator.num_pages|subtract:'3' == page.number %}
                                                <li><a href="?q={{query}}&amp;page={{ page.number|add:'1' }}">{{ page.number|add:'1' }}</a></li>
                                                <li><a href="?q={{query}}&amp;page={{ page.number|add:'2' }}">{{ page.number|add:'2' }}</a></li>
                                                <li><a href="?q={{query}}&amp;page={{ page.number|add:'3' }}">{{ page.number|add:'3' }}</a></li>
                                            {% endif %}
                                            {% if paginator.num_pages|subtract:'2' == page.number %}
                                                <li><a href="?q={{query}}&amp;page={{ page.number|add:'1' }}">{{ page.number|add:'1' }}</a></li>
                                                <li><a href="?q={{query}}&amp;page={{ page.number|add:'2' }}">{{ page.number|add:'2' }}</a></li>
                                            {% endif %}
                                            {% if paginator.num_pages|subtract:'1' == page.number %}
                                                <li><a href="?q={{query}}&amp;page={{ page.number|add:'1' }}">{{ page.number|add:'1' }}</a></li>
                                            {% endif %}
                                        {% endif %}
                                    {% endif %}
                                    {# 下一页 #}
                                    {% if page.has_next %}
                                        <li><a href="?q={{query}}&amp;page={{ page.next_page_number }}">
                                            <span aria-hidden="true">&raquo;</span></a></li>
                                     {% else %}
                                          <li class="disabled"><a href="javascript:void(0);">
                                              <span aria-hidden="false">&raquo;</span></a></li>
                                     {% endif %}
                            </ul>
                        </nav>
                        </div>
                            {% endif %}
                        {% endif %}
                    </main>
                </div>
			</div>
		</div>
{% endblock %}


